import {Color} from 'cc';

export interface LevelInfo {
    title: string;
    star: number;
    background: Color;
    background2?: Color;
    background3?: Color;
    background4?: Color;
    fontColor: Color;
}


export enum Game2048LevelEnum {
    LV1 = "LV1",
    LV2 = "LV2",
    LV3 = "LV3",
    LV4 = "LV4",
    LV6 = "LV6",
    LV7 = "LV7",
    LV8 = "LV8",
    LV9 = "LV9",
    LV10 = "LV10",
    LV11 = "LV11",
    LV12 = "LV12",
    LV13 = "LV13",
    LV14 = "LV14",
    LV15 = "LV15",
    LV16 = "LV16",
    LV17 = "LV17",
    LV18 = "LV18",
    LV19 = "LV19",
    LV20 = "LV20",
    LV21 = "LV21",
    LV22 = "LV22",
    LV23 = "LV23",
    LV24 = "LV24",
    LV25 = "LV25",
    LV26 = "LV26",
    LV27 = "LV27",
    LV28 = "LV28",
    LV29 = "LV29",
    LV30 = "LV30"
}

export const levelEnumInfo: Record<string, LevelInfo> = {
    [Game2048LevelEnum.LV1]: {
        title: "练气前期",
        star: 3,
        background: new Color(200, 230, 200),
        fontColor: new Color(50, 50, 50)
    },
    [Game2048LevelEnum.LV2]: {
        title: "练气中期",
        star: 3,
        background: new Color(180, 210, 180),
        fontColor: new Color(40, 40, 40)
    },
    [Game2048LevelEnum.LV3]: {title: "练气后期", star: 3, background: new Color(160, 190, 160), fontColor: Color.WHITE},
    [Game2048LevelEnum.LV4]: {
        title: "练气大圆满",
        star: 3,
        background: new Color(140, 170, 140),
        fontColor: Color.WHITE
    },

    // 筑基期：青绿色系
    [Game2048LevelEnum.LV6]: {
        title: "筑基前期",
        star: 3,
        background: new Color(180, 240, 220),
        fontColor: new Color(0, 100, 80)
    },
    [Game2048LevelEnum.LV7]: {
        title: "筑基中期",
        star: 3,
        background: new Color(160, 220, 200),
        fontColor: new Color(0, 80, 60)
    },
    [Game2048LevelEnum.LV8]: {title: "筑基后期", star: 3, background: new Color(140, 200, 180), fontColor: Color.WHITE},
    [Game2048LevelEnum.LV9]: {
        title: "筑基大圆满",
        star: 3,
        background: new Color(120, 180, 160),
        fontColor: Color.WHITE
    },

    // 金丹期：金色系
    [Game2048LevelEnum.LV10]: {
        title: "金丹前期",
        star: 5,
        background: new Color(255, 240, 160),
        fontColor: new Color(120, 60, 0)
    },
    [Game2048LevelEnum.LV11]: { // 金丹中期
        title: "金丹中期",
        star: 5,
        background: new Color(255, 220, 120),
        fontColor: new Color(100, 50, 0)
    },
    [Game2048LevelEnum.LV12]: { // 金丹后期
        title: "金丹后期",
        star: 5,
        background: new Color(255, 200, 100),
        fontColor: new Color(90, 45, 0)
    },
    [Game2048LevelEnum.LV13]: {
        title: "金丹大圆满",
        star: 5,
        background: new Color(255, 200, 80),
        fontColor: new Color(80, 40, 0)
    },

    // 元婴期：蓝色系
    [Game2048LevelEnum.LV14]: {
        title: "元婴前期",
        star: 5,
        background: new Color(180, 220, 255),
        fontColor: new Color(0, 50, 120)
    },

    [Game2048LevelEnum.LV15]: { // 元婴中期
        title: "元婴中期",
        star: 5,
        background: new Color(140, 180, 255),
        fontColor: new Color(0, 30, 90)
    },
    [Game2048LevelEnum.LV16]: { // 元婴后期
        title: "元婴后期",
        star: 5,
        background: new Color(100, 160, 255),
        fontColor: Color.WHITE
    },

    [Game2048LevelEnum.LV17]: {
        title: "元婴大圆满",
        star: 5,
        background: new Color(80, 140, 255),
        fontColor: Color.WHITE
    },

    // 化神期：紫色系
    [Game2048LevelEnum.LV18]: {
        title: "化神前期",
        star: 6,
        background: new Color(220, 180, 255),
        background2: new Color(180, 120, 220),
        fontColor: new Color(60, 0, 80)
    },
    [Game2048LevelEnum.LV19]: {
        title: "化神中期",
        star: 6,
        background: new Color(200, 140, 240),
        background2: new Color(160, 100, 220),
        fontColor: new Color(40, 0, 60)
    },
    [Game2048LevelEnum.LV20]: {
        title: "化神后期",
        star: 6,
        background: new Color(180, 120, 220),
        background2: new Color(140, 80, 200),
        fontColor: Color.WHITE
    },
    [Game2048LevelEnum.LV21]: {
        title: "化神大圆满",
        star: 6,
        background: new Color(160, 100, 220),
        background2: new Color(120, 60, 180),
        fontColor: Color.WHITE
    },

    // 渡劫期：红色系
    [Game2048LevelEnum.LV22]: {
        title: "渡劫前期",
        star: 6,
        background: new Color(255, 200, 200),
        background2: new Color(200, 50, 50),
        fontColor: new Color(120, 0, 0)
    },
    [Game2048LevelEnum.LV23]: {
        title: "渡劫中期",
        star: 6,
        background: new Color(230, 100, 100),
        background2: new Color(180, 30, 30),
        fontColor: Color.WHITE
    },
    [Game2048LevelEnum.LV24]: {
        title: "渡劫后期",
        star: 6,
        background: new Color(200, 50, 50),
        background2: new Color(160, 10, 10),
        fontColor: Color.WHITE
    },
    [Game2048LevelEnum.LV25]: {
        title: "渡劫大圆满",
        star: 6,
        background: new Color(200, 0, 0),
        background2: new Color(120, 0, 0),
        fontColor: Color.WHITE
    },

    // 飞升期：彩虹渐变
    [Game2048LevelEnum.LV26]: {
        title: "飞升前期",
        star: 9,
        background: new Color(255, 150, 150),
        background2: new Color(200, 200, 200),
        fontColor: new Color(80, 0, 0)
    },
    [Game2048LevelEnum.LV27]: {
        title: "飞升中期",
        star: 9,
        background: new Color(200, 200, 200),
        background2: new Color(180, 180, 255),
        fontColor: new Color(40, 40, 40)
    },
    [Game2048LevelEnum.LV28]: {
        title: "飞升后期",
        star: 9,
        background: new Color(180, 180, 255),
        background2: new Color(150, 150, 255),
        fontColor: new Color(0, 0, 60)
    },
    [Game2048LevelEnum.LV29]: {
        title: "飞升大圆满",
        star: 9,
        background: new Color(150, 150, 255),
        background2: new Color(120, 120, 255),
        fontColor: new Color(0, 0, 80)
    },

    // 仙人：金色渐变
    [Game2048LevelEnum.LV30]: {
        title: "仙人",
        star: 10,
        background: new Color(255, 215, 140),
        background2: new Color(255, 165, 0),
        fontColor: new Color(120, 60, 0)
    }
};


export function getNextLevel(currentLevel: Game2048LevelEnum): Game2048LevelEnum | undefined {
    // 获取枚举的键数组，顺序与声明顺序一致
    const keys = Object.keys(Game2048LevelEnum) as Array<keyof typeof Game2048LevelEnum>;
    // 将当前枚举值转换为对应的键（假设值与键名相同）
    const currentKey = currentLevel as keyof typeof Game2048LevelEnum;
    const currentIndex = keys.indexOf(currentKey);

    // 如果找不到当前索引或已经是最后一位，返回undefined
    if (currentIndex === -1 || currentIndex === keys.length - 1) {
        return null;
    }

    // 获取下一个键并返回对应的枚举值
    const nextKey = keys[currentIndex + 1];
    return Game2048LevelEnum[nextKey];
}

export function getBeforeLevel(currentLevel: Game2048LevelEnum): Game2048LevelEnum | undefined {
    // 获取枚举的键数组，顺序与声明顺序一致
    const keys = Object.keys(Game2048LevelEnum) as Array<keyof typeof Game2048LevelEnum>;
    // 将当前枚举值转换为对应的键（假设值与键名相同）
    const currentKey = currentLevel as keyof typeof Game2048LevelEnum;
    const currentIndex = keys.indexOf(currentKey);

    // 如果找不到当前索引或已经是最后一位，返回undefined
    if (currentIndex === -1 || currentIndex === 0) {
        return null;
    }

    // 获取下一个键并返回对应的枚举值
    const nextKey = keys[currentIndex - 1];
    return Game2048LevelEnum[nextKey];
}

